package com.ymatou.iapi.accounting.testcase;

import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.accounting.parameter.*;
import com.ymatou.iapi.accounting.service.*;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.AccountCallServiceV2;
import com.ymttest.database.model.Account;
import com.ymttest.database.sqlwapper.AccountWapper;
import com.ymttest.utils.EnvSetup;
/**
*锁定解锁账户接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SetAccountLockStatus{
	private static SetAccountLockStatusBean setaccountlockstatusBean;
	private static SetAccountLockStatusCall setaccountlockstatusCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("锁定解锁账户接口");
	}

	@Before
	public void caseUp() {
		setaccountlockstatusBean=new SetAccountLockStatusBean();
		setaccountlockstatusCall=new SetAccountLockStatusCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(setaccountlockstatusCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SetAccountLockStatus_001() {
		Logger.start(true,"锁定账户成功");
		try {
			String aid=AccountCallServiceV2.getAccountId(Integer.valueOf(EnvSetup.getData("accountuid1")));
			setaccountlockstatusBean.setAccountId(aid);
			setaccountlockstatusBean.setStatus(1);
			setaccountlockstatusBean.setAppId("AutoTest");
			setaccountlockstatusBean.setMemo("自动化测试Lock");
			setaccountlockstatusCall.setData(setaccountlockstatusBean);
			setaccountlockstatusCall.callService();			
			Logger.verifyEquals("0", setaccountlockstatusCall.getStatus(), "验证返回状态为0,操作成功");		
			List<Account> aids= new AccountWapper().selectAccountInfo(aid);			 
			Logger.verifyEquals(1, (Integer)aids.get(0).getStatus(), "验证数据库账户状态为1锁定");	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SetAccountLockStatus_002() {
		Logger.start(true,"解锁账户成功");
		try {
			String aid=AccountCallServiceV2.getAccountId(Integer.valueOf(EnvSetup.getData("accountuid1")));
			setaccountlockstatusBean.setAccountId(aid);
			setaccountlockstatusBean.setStatus(0);
			setaccountlockstatusBean.setAppId("AutoTest");
			setaccountlockstatusBean.setMemo("自动化测试Lock");
			setaccountlockstatusCall.setData(setaccountlockstatusBean);
			setaccountlockstatusCall.callService();			
			Logger.verifyEquals("0", setaccountlockstatusCall.getStatus(), "验证返回状态为0,操作成功");		
			List<Account> aids= new AccountWapper().selectAccountInfo(aid);			 
			Logger.verifyEquals(0, (Integer)aids.get(0).getStatus(), "验证数据库账户状态为0可用");	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_SetAccountLockStatus_003() {
		Logger.start(true,"同一个账户编号重复锁定");
		try {
			String aid=AccountCallServiceV2.getAccountId(Integer.valueOf(EnvSetup.getData("accountuid1")));
			setaccountlockstatusBean.setAccountId(aid);
			setaccountlockstatusBean.setStatus(1);
			setaccountlockstatusBean.setAppId("AutoTest");
			setaccountlockstatusBean.setMemo("自动化测试Lock");
			setaccountlockstatusCall.setData(false,setaccountlockstatusBean);
			setaccountlockstatusCall.callService();			
			Logger.verifyEquals("0", setaccountlockstatusCall.getStatus(), "验证返回状态为0,操作成功");		
			List<Account> aids= new AccountWapper().selectAccountInfo(aid);			 
			Logger.verifyEquals(1, (Integer)aids.get(0).getStatus(), "验证数据库账户状态为1锁定");		
			//第二次重复锁定
			Logger.comment("第二次重复锁定");
			setaccountlockstatusCall.setData(setaccountlockstatusBean);
			setaccountlockstatusCall.callService();				
			aids= new AccountWapper().selectAccountInfo(aid);			 
			Logger.verifyEquals("0", setaccountlockstatusCall.getStatus(), "验证返回状态为0,操作成功");		
			Logger.verifyEquals(1, (Integer)aids.get(0).getStatus(), "验证数据库账户状态为1锁定");	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_SetAccountLockStatus_004() {
		Logger.start(true,"同一个账户编号重复解锁,操作成功");
		try {
			String aid=AccountCallServiceV2.getAccountId(Integer.valueOf(EnvSetup.getData("accountuid1")));
			setaccountlockstatusBean.setAccountId(aid);
			setaccountlockstatusBean.setStatus(0);
			setaccountlockstatusBean.setAppId("AutoTest");
			setaccountlockstatusBean.setMemo("自动化测试Lock");
			setaccountlockstatusCall.setData(false,setaccountlockstatusBean);
			setaccountlockstatusCall.callService();			
			Logger.verifyEquals("0", setaccountlockstatusCall.getStatus(), "验证返回状态为0,操作成功");		
			List<Account> aids= new AccountWapper().selectAccountInfo(aid);			 
			Logger.verifyEquals(0, (Integer)aids.get(0).getStatus(), "验证数据库账户状态为0可用");	
			Logger.comment("第二次重复锁定");
			setaccountlockstatusCall.setData(setaccountlockstatusBean);
			setaccountlockstatusCall.callService();				
			aids= new AccountWapper().selectAccountInfo(aid);			 
			Logger.verifyEquals("0", setaccountlockstatusCall.getStatus(), "验证返回状态为0,操作成功");		
			Logger.verifyEquals(0, (Integer)aids.get(0).getStatus(), "验证数据库账户状态为0可用");	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_SetAccountLockStatus_005() {
		Logger.start(false,"对已锁定账户,操作解锁外其它操作如status为2");
		try {
			//锁定账户
			String aid=AccountCallServiceV2.getAccountId(Integer.valueOf(EnvSetup.getData("accountuid1")));
			setaccountlockstatusBean.setAccountId(aid);
			setaccountlockstatusBean.setStatus(1);
			setaccountlockstatusBean.setAppId("AutoTest");
			setaccountlockstatusBean.setMemo("自动化测试Lock");
			setaccountlockstatusCall.setData(setaccountlockstatusBean);
			setaccountlockstatusCall.callService();			
			Logger.verifyEquals("0", setaccountlockstatusCall.getStatus(), "验证返回状态为0,操作成功");		
			List<Account> aids= new AccountWapper().selectAccountInfo(aid);			 
			Logger.verifyEquals(1, (Integer)aids.get(0).getStatus(), "验证数据库账户状态为1锁定");	
			//操作操作解锁外其它操作如status为2
			Logger.comment("操作操作解锁外其它操作如status为2,期望提示错误信息");
			setaccountlockstatusBean.setStatus(2);
			setaccountlockstatusCall.setData(setaccountlockstatusBean);
			setaccountlockstatusCall.callService();		
			Logger.comment("setaccountlockstatusCall send:" + setaccountlockstatusCall.getEntityString());
			Logger.comment("setaccountlockstatusCall response:" + setaccountlockstatusCall.getReturnData());	
			Logger.verifyEquals("2", setaccountlockstatusCall.getStatus(), "验证返回状态为0,操作成功");		
			Logger.verifyIsContains("Status不能为空", setaccountlockstatusCall.getMsg(), "验证错误提示信息");		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_SetAccountLockStatus_006() {
		Logger.start(false,"账户编号不存在,锁定解锁操作失败");
		try {
			String aid="0000000000";
			setaccountlockstatusBean.setAccountId(aid);
			setaccountlockstatusBean.setStatus(1);
			setaccountlockstatusBean.setAppId("AutoTest");
			setaccountlockstatusBean.setMemo("自动化测试Lock");
			setaccountlockstatusCall.setData(setaccountlockstatusBean);
			setaccountlockstatusCall.callService();			
			Logger.verifyEquals("3", setaccountlockstatusCall.getStatus(), "验证返回状态");		
			Logger.verifyEquals("更新账户状态失败！", setaccountlockstatusCall.getMsg(), "验证错误提示信息");		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_SetAccountLockStatus_007() {
		Logger.start(false,"账户状态不存在如3,锁定解锁操作失败");
		try {
			String aid=AccountCallServiceV2.getAccountId(Integer.valueOf(EnvSetup.getData("accountuid1")));
			setaccountlockstatusBean.setAccountId(aid);
			setaccountlockstatusBean.setStatus(3);
			setaccountlockstatusBean.setAppId("AutoTest");
			setaccountlockstatusBean.setMemo("自动化测试Lock");
			setaccountlockstatusCall.setData(setaccountlockstatusBean);
			setaccountlockstatusCall.callService();			
			Logger.verifyEquals("2", setaccountlockstatusCall.getStatus(), "验证返回状态");		
			Logger.verifyIsContains("Status不能为空", setaccountlockstatusCall.getMsg(), "验证错误提示信息");		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_SetAccountLockStatus_008() {
		Logger.start(false,"账户编号为空,锁定解锁操作失败");
		try {
			String aid="00010020000000";
			//setaccountlockstatusBean.setAccountId(aid);
			setaccountlockstatusBean.setStatus(3);
			setaccountlockstatusBean.setAppId("AutoTest");
			setaccountlockstatusBean.setMemo("自动化测试Lock");
			setaccountlockstatusCall.setData(setaccountlockstatusBean);
			setaccountlockstatusCall.callService();			
			Logger.verifyEquals("2", setaccountlockstatusCall.getStatus(), "验证返回状态");		
			Logger.verifyEquals("AccountId不能为空！", setaccountlockstatusCall.getMsg(), "验证错误提示信息");		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_SetAccountLockStatus_009() {
		Logger.start(true,"账户状态为空,失败");
		try {
			String aid=AccountCallServiceV2.getAccountId(Integer.valueOf(EnvSetup.getData("accountuid1")));
			setaccountlockstatusBean.setAccountId(aid);
			//setaccountlockstatusBean.setStatus(3);
			setaccountlockstatusBean.setAppId("AutoTest");
			setaccountlockstatusBean.setMemo("自动化测试Lock");
			setaccountlockstatusCall.setData(setaccountlockstatusBean);
			setaccountlockstatusCall.callService();			
			Logger.verifyEquals("2", setaccountlockstatusCall.getStatus(), "验证返回状态");		
			Logger.verifyIsContains("Status不能为空", setaccountlockstatusCall.getMsg(), "验证错误提示信息");		
			List<Account> aids= new AccountWapper().selectAccountInfo(aid);			 
			Logger.verifyEquals(1, (Integer)aids.get(0).getStatus(), "验证数据库账户状态为0可用");	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_SetAccountLockStatus_010() {
		Logger.start(false,"应用编号为空,锁定解锁操作失败");
		try {
			String aid=AccountCallServiceV2.getAccountId(Integer.valueOf(EnvSetup.getData("accountuid1")));
			setaccountlockstatusBean.setAccountId(aid);
			setaccountlockstatusBean.setStatus(0);
			//setaccountlockstatusBean.setAppId("AutoTest");
			setaccountlockstatusBean.setMemo("自动化测试Lock");
			setaccountlockstatusCall.setData(setaccountlockstatusBean);
			setaccountlockstatusCall.callService();			
			Logger.verifyEquals("2", setaccountlockstatusCall.getStatus(), "验证返回状态");		
			Logger.verifyEquals("AppId不能为空！", setaccountlockstatusCall.getMsg(), "验证错误提示信息");	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_SetAccountLockStatus_011() {
		Logger.start(false,"备注为空,锁定解锁操作失败");
		try {
			String aid=AccountCallServiceV2.getAccountId(Integer.valueOf(EnvSetup.getData("accountuid1")));
			setaccountlockstatusBean.setAccountId(aid);
			setaccountlockstatusBean.setStatus(0);
			setaccountlockstatusBean.setAppId("AutoTest");
			//setaccountlockstatusBean.setMemo("自动化测试Lock");
			setaccountlockstatusCall.setData(setaccountlockstatusBean);
			setaccountlockstatusCall.callService();			
			Logger.verifyEquals("2", setaccountlockstatusCall.getStatus(), "验证返回状态");		
			Logger.verifyEquals("Memo不能为空！", setaccountlockstatusCall.getMsg(), "验证错误提示信息");	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}